﻿﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using verk2013_project_group12.Models;

namespace verk2013_project_group12.Models
{
    public class GameRegistrationRepository
    {
        AppDataContext db = new AppDataContext();

        public IEnumerable<GameRegistration> GetAllRegistrations()
        {
            return db.GameRegistrations;
        }

        public IEnumerable<GameRegistration> GetRegistrationsByInstId(int id)
        {
            var theRegistrations = from r in db.GameRegistrations
                                   where r.InstanceID == id
                                   select r;

            return theRegistrations;
        }

        public void Add(GameRegistration registration)
        {
            db.GameRegistrations.Add(registration);
            
        }

        public void Save()
        {
            db.SaveChanges();
        }

        public void Remove(GameRegistration registration)
        {
            if (registration != null)
            {
                db.GameRegistrations.Attach(registration);
                db.GameRegistrations.Remove(registration);
            }
        }

    }
}